package com.xuyuan.concurrent.lock;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.StampedLock;

public class ReadWriteLockTest {
    private static final ReadWriteLock LOCK = new ReentrantReadWriteLock();
    private static final StampedLock  STAMPEDLOCK = new StampedLock();

    public static void main(String[] args) {
/*        try {
            LOCK.writeLock().tryLock(1, TimeUnit.MINUTES);
            Lock lock1 = LOCK.readLock();
            Lock lock2 = LOCK.writeLock();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }*/
        long stamp = STAMPEDLOCK.tryReadLock();
        if (stamp != 0) {
            try {
                System.out.println("read");
            } finally {
                STAMPEDLOCK.unlockRead(stamp);
            }
        }
    }
}
